package com.ts.mapper.achievement;

import com.ts.entity.Monograph;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MonographMapper {

    /**
     * 存入一条专著成果数据并且主键返回
     * @param monograph
     */
    @Insert("INSERT INTO `tianshi-college-teacher-system-test`.ts_monograph " +
            "(name, author, ranks, isbn, mono_type, " +
            "subject, source_name, source_level, publisher, pub_time, " +
            "college, achievement_type, is_first_principal, is_first_in_unit, " +
            "remark, audit_materials, submit_user_id, submit_time, audit_status, " +
            "create_by, create_time, update_by, update_time) VALUES (" +
            "#{name}, #{author}, #{ranks}, #{isbn}, #{monoType}, " +
            "#{subject}, #{sourceName}, #{sourceLevel}, #{publisher}, #{pubTime}, " +
            "#{college}, #{achievementType}, #{isFirstPrincipal}, #{isFirstInUnit}, " +
            "#{remark}, #{auditMaterials}, #{submitUserId}, #{submitTime}, #{auditStatus}, " +
            "#{createBy}, #{createTime}, #{updateBy}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void save(Monograph monograph);
    @Update("UPDATE `tianshi-college-teacher-system-test`.ts_monograph SET " +
            "name = #{name}, author = #{author}, ranks = #{ranks}, isbn = #{isbn}, mono_type = #{monoType}, " +
            "subject = #{subject}, source_name = #{sourceName}, source_level = #{sourceLevel}, publisher = #{publisher}, pub_time = #{pubTime}, " +
            "college = #{college}, achievement_type = #{achievementType}, is_first_principal = #{isFirstPrincipal}, is_first_in_unit = #{isFirstInUnit}, " +
            "remark = #{remark}, audit_materials = #{auditMaterials}, update_by = #{updateBy}, update_time = #{updateTime} " +
            "WHERE id = #{id}")
    void updateById(Monograph monograph);

    @Delete("DELETE FROM `tianshi-college-teacher-system-test`.ts_monograph WHERE id = #{id}")
    void deleteById(Long id);

    @Select("SELECT * FROM `tianshi-college-teacher-system-test`.ts_monograph WHERE id = #{id}")
    Monograph selectById(Long id);

    @Select("SELECT * FROM `tianshi-college-teacher-system-test`.ts_monograph")
    List<Monograph> selectAll();
}
